package com.ruoyi.supplier.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supplier.domain.GysMainCategory;
import com.ruoyi.supplier.service.IGysMainCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 品项类别Controller
 * 
 * @author ruoyi
 * @date 2024-07-15
 */
@RestController
@RequestMapping("/supplier/item")
public class GysMainCategoryController extends BaseController
{
    @Autowired
    private IGysMainCategoryService gysMainCategoryService;

    /**
     * 查询品项类别列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:item:list')")
    @GetMapping("/list")
    public AjaxResult list(GysMainCategory gysMainCategory)
    {
        List<GysMainCategory> list = gysMainCategoryService.selectGysMainCategoryList(gysMainCategory);
        return success(list);
    }

    /**
     * 导出品项类别列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:item:export')")
    @Log(title = "品项类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GysMainCategory gysMainCategory)
    {
        List<GysMainCategory> list = gysMainCategoryService.selectGysMainCategoryList(gysMainCategory);
        ExcelUtil<GysMainCategory> util = new ExcelUtil<GysMainCategory>(GysMainCategory.class);
        util.exportExcel(response, list, "品项类别数据");
    }

    /**
     * 获取品项类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('supplier:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gysMainCategoryService.selectGysMainCategoryById(id));
    }

    /**
     * 新增品项类别
     */
    @PreAuthorize("@ss.hasPermi('supplier:item:add')")
    @Log(title = "品项类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GysMainCategory gysMainCategory)
    {
        return toAjax(gysMainCategoryService.insertGysMainCategory(gysMainCategory));
    }

    /**
     * 修改品项类别
     */
    @PreAuthorize("@ss.hasPermi('supplier:item:edit')")
    @Log(title = "品项类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GysMainCategory gysMainCategory)
    {
        return toAjax(gysMainCategoryService.updateGysMainCategory(gysMainCategory));
    }

    /**
     * 删除品项类别
     */
    @PreAuthorize("@ss.hasPermi('supplier:item:remove')")
    @Log(title = "品项类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gysMainCategoryService.deleteGysMainCategoryByIds(ids));
    }
}
